<template>
  <div class="hello">
    <van-tabbar v-model="active" class="active_tab">
      <van-tabbar-item 
       v-for='(item,index) in tabbars'
       :key="index"
       @click="tab(index,item.name)"
       >
        <span :class="currIndex == index ? active:''">{{item.title}}</span>
        <template slot="icon" slot-scope="props">
          <img :src="props.active ? item.active : item.normal">
        </template>
        </van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
import { Tabbar, TabbarItem } from 'vant'
export default {
  name: 'Tabbar',
  components: {
    [Tabbar.name]: Tabbar,
    [TabbarItem.name]: TabbarItem
  },
  data () {
    return {
      currIndex: 0,
      active: 0,
      tabbars: [
        { 
          name: 'home',
          title: '关键指标',
          normal: 'https://img.yzcdn.cn/vant/user-inactive.png',
          active: 'https://img.yzcdn.cn/vant/user-active.png'
        },
        { 
          name: 'shore',
          title: '专题分析',
          normal: 'https://img.yzcdn.cn/vant/user-inactive.png',
          active: 'https://img.yzcdn.cn/vant/user-active.png'
        },
        { 
          name: 'my',
          title: '我的',
          normal: 'https://img.yzcdn.cn/vant/user-inactive.png',
          active: 'https://img.yzcdn.cn/vant/user-active.png'
        }
      ]
    }
  },
 methods: {
    tab(index, val) {
      this.currIndex = index;
      this.$router.push(val);
    }
  }
}
</script>

<style lang='less' scoped>
.active_tab img {
  width: 26px;
  height: 26px;
}

.van-tabbar-item--active {
  color: #1989fa;
}

</style>